home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / flip / flip.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-12-05  |  8.9 KB  |  227 lines

  1. VERSION 2.00
  2. Begin Form Flip 
  3.    BackColor       =   &H00FF0000&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Flip"
  6.    ClientHeight    =   4950
  7.    ClientLeft      =   1185
  8.    ClientTop       =   1500
  9.    ClientWidth     =   4950
  10.    FontBold        =   -1  'True
  11.    FontItalic      =   0   'False
  12.    FontName        =   "System"
  13.    FontSize        =   9.75
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   5355
  17.    Icon            =   FLIP.FRX:0000
  18.    Left            =   1125
  19.    LinkMode        =   1  'Source
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    MinButton       =   0   'False
  23.    ScaleHeight     =   330
  24.    ScaleMode       =   3  'Pixel
  25.    ScaleWidth      =   330
  26.    Top             =   1155
  27.    Width           =   5070
  28.    Begin PictureBox Picture1 
  29.       AutoRedraw      =   -1  'True
  30.       AutoSize        =   -1  'True
  31.       BorderStyle     =   0  'None
  32.       FontBold        =   -1  'True
  33.       FontItalic      =   0   'False
  34.       FontName        =   "System"
  35.       FontSize        =   9.75
  36.       FontStrikethru  =   0   'False
  37.       FontUnderline   =   0   'False
  38.       Height          =   990
  39.       Left            =   270
  40.       Picture         =   FLIP.FRX:0302
  41.       ScaleHeight     =   66
  42.       ScaleMode       =   0  'User
  43.       ScaleWidth      =   66
  44.       TabIndex        =   0
  45.       Top             =   840
  46.       Visible         =   0   'False
  47.       Width           =   990
  48.    End
  49.    Begin PictureBox Picture3 
  50.       AutoRedraw      =   -1  'True
  51.       AutoSize        =   -1  'True
  52.       BorderStyle     =   0  'None
  53.       FontBold        =   -1  'True
  54.       FontItalic      =   0   'False
  55.       FontName        =   "System"
  56.       FontSize        =   9.75
  57.       FontStrikethru  =   0   'False
  58.       FontUnderline   =   0   'False
  59.       Height          =   990
  60.       Left            =   1290
  61.       Picture         =   FLIP.FRX:0CC4
  62.       ScaleHeight     =   66
  63.       ScaleMode       =   0  'User
  64.       ScaleWidth      =   66
  65.       TabIndex        =   2
  66.       Top             =   840
  67.       Visible         =   0   'False
  68.       Width           =   990
  69.    End
  70.    Begin PictureBox Picture5 
  71.       AutoRedraw      =   -1  'True
  72.       AutoSize        =   -1  'True
  73.       BorderStyle     =   0  'None
  74.       FontBold        =   -1  'True
  75.       FontItalic      =   0   'False
  76.       FontName        =   "System"
  77.       FontSize        =   9.75
  78.       FontStrikethru  =   0   'False
  79.       FontUnderline   =   0   'False
  80.       Height          =   990
  81.       Left            =   2340
  82.       Picture         =   FLIP.FRX:1686
  83.       ScaleHeight     =   66
  84.       ScaleMode       =   0  'User
  85.       ScaleWidth      =   66
  86.       TabIndex        =   4
  87.       Top             =   840
  88.       Visible         =   0   'False
  89.       Width           =   990
  90.    End
  91.    Begin PictureBox Picture2 
  92.       AutoRedraw      =   -1  'True
  93.       BorderStyle     =   0  'None
  94.       FontBold        =   -1  'True
  95.       FontItalic      =   0   'False
  96.       FontName        =   "System"
  97.       FontSize        =   9.75
  98.       FontStrikethru  =   0   'False
  99.       FontUnderline   =   0   'False
  100.       Height          =   990
  101.       Left            =   3480
  102.       ScaleHeight     =   66
  103.       ScaleMode       =   0  'User
  104.       ScaleWidth      =   66
  105.       TabIndex        =   1
  106.       Top             =   840
  107.       Visible         =   0   'False
  108.       Width           =   990
  109.    End
  110.    Begin PictureBox Picture4 
  111.       AutoRedraw      =   -1  'True
  112.       BorderStyle     =   0  'None
  113.       FontBold        =   -1  'True
  114.       FontItalic      =   0   'False
  115.       FontName        =   "System"
  116.       FontSize        =   9.75
  117.       FontStrikethru  =   0   'False
  118.       FontUnderline   =   0   'False
  119.       Height          =   480
  120.       Left            =   0
  121.       Picture         =   FLIP.FRX:2048
  122.       ScaleHeight     =   32
  123.       ScaleMode       =   0  'User
  124.       ScaleWidth      =   800
  125.       TabIndex        =   3
  126.       Top             =   3120
  127.       Visible         =   0   'False
  128.       Width           =   12000
  129.    End
  130. Declare Function BitBlt% Lib "gdi" (ByVal destDC%, ByVal x%, ByVal Y%, ByVal w%, ByVal H%, ByVal srcDC%, ByVal xSrc%, ByVal ySrc%, ByVal Rop&)
  131. Declare Function StretchBlt% Lib "gdi" (ByVal destDC%, ByVal x%, ByVal Y%, ByVal w%, ByVal H%, ByVal srcDC%, ByVal xSrc%, ByVal ySrc%, ByVal wSrc%, ByVal hSrc%, ByVal Rop&)
  132. Const SRCCOPY = &HCC0020
  133. Dim cxBorders%, cyBorders%, Flipped%(63)
  134. Sub Form_Load ()
  135.    x% = MsgBox("- Left button flips cells" + Chr$(13) + "- Right button X's out Cells", 0, "Mouse buttons")
  136.    Picture2.BackColor = Flip.BackColor
  137.    Picture2.Height = Picture1.Height
  138.    Picture2.Width = Picture1.Width
  139. End Sub
  140. Sub Form_MouseUp (Button As Integer, Shift As Integer, x As Single, Y As Single)
  141. '* Determine what Cell was clicked and what Icon should
  142. '* be displayed when flipped.
  143.   IX% = x \ Picture1.Width
  144.   IY% = Y \ Picture1.Height
  145.   IconNum% = IX% + (IY% * 5)
  146. '* Determine upper left hand corner of Cell within form
  147.   IX% = IX% * Picture1.Width
  148.   IY% = IY% * Picture1.Height
  149. '* Copy Icon from IconsBitmap to middle of "Working"
  150. '* Picture control in preparation for flipping.
  151. '* If displaying the Icon, The icon is inverted horizontally
  152. '* before flipping so when it is flipped, it appears normally
  153.   If Button = 1 Then
  154.     If Flipped%(IconNum%) Then
  155.       Z% = BitBlt(Picture3.hDC, 18, 18, 32, 32, Picture4.hDC, IconNum% * 32, 0, SRCCOPY)
  156.     Else
  157.       Z% = StretchBlt(Picture3.hDC, 49, 18, -32, 32, Picture4.hDC, IconNum% * 32, 0, 32, 32, SRCCOPY)
  158.     End If
  159.     FlipWidth% = Picture1.Width
  160.   '* Flip the Cell
  161.     For I% = 0 To Picture1.Width Step 10
  162.       Picture2.Cls
  163.       If Flipped%(IconNum%) Then
  164.       '* Flip cell horizontally
  165.         If ((Not Flipped%(IconNum%)) And (I% < Picture1.Width \ 2)) Or (Flipped%(IconNum%) And (I% >= Picture1.Width \ 2)) Then
  166.           Z% = StretchBlt(Picture2.hDC, 0, I%, Picture1.Height, FlipWidth%, Picture1.hDC, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
  167.         Else
  168.           Z% = StretchBlt(Picture2.hDC, 0, I%, Picture1.Height, FlipWidth%, Picture3.hDC, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
  169.         End If
  170.       Else
  171.       '* Flip cell Vertically
  172.         If ((Not Flipped%(IconNum%)) And (I% < Picture1.Width \ 2)) Or (Flipped%(IconNum%) And (I% >= Picture1.Width \ 2)) Then
  173.           Z% = StretchBlt(Picture2.hDC, I%, 0, FlipWidth%, Picture1.Height, Picture1.hDC, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
  174.         Else
  175.           Z% = StretchBlt(Picture2.hDC, I%, 0, FlipWidth%, Picture1.Height, Picture3.hDC, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
  176.         End If
  177.       End If
  178.     '* Display partially flipped Cell on Form
  179.       Z% = BitBlt(hDC, IX%, IY%, Picture1.Width, Picture1.Height, Picture2.hDC, 0, 0, SRCCOPY)
  180.       FlipWidth% = FlipWidth% - 20
  181.     Next
  182.     Flipped%(IconNum%) = Not Flipped%(IconNum%)
  183.    '* Display final cell on Form, either Icon cell or
  184.    '* or normal unflipped cell background
  185.     If Flipped%(IconNum%) Then
  186.       Z% = BitBlt(Picture3.hDC, 18, 18, 32, 32, Picture4.hDC, IconNum% * 32, 0, SRCCOPY)
  187.       Z% = BitBlt(hDC, IX%, IY%, Picture1.Width, Picture1.Height, Picture3.hDC, 0, 0, SRCCOPY)
  188.     Else
  189.       Z% = BitBlt(hDC, IX%, IY%, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, SRCCOPY)
  190.     End If
  191.   ElseIf Button = 2 Then
  192. '* X out cell
  193.     XWidth% = 2
  194.     For I% = (Picture1.Width \ 2) - 2 To 0 Step -4
  195.       Z% = StretchBlt(hDC, IX% + I%, IY% + I%, XWidth%, XWidth%, Picture5.hDC, 0, 0, CInt(Picture1.Width - 2), CInt(Picture1.Height - 2), SRCCOPY)
  196.       XWidth% = XWidth% + 8
  197.     Next
  198.     Z% = BitBlt(hDC, IX%, IY%, Picture1.Width, Picture1.Height, Picture5.hDC, 0, 0, SRCCOPY)
  199.   End If
  200. End Sub
  201. Sub Form_Paint ()
  202. '* Repaint form row by row, copying normal backgroup
  203. '* cell bitmap to form if cell is not flipped, or the
  204. '* corresponding Icon if the cell is flipped.
  205.   For Row% = 0 To 4
  206.     For Columns% = 0 To 4
  207.     '* Determine upper left hand corner of Cell
  208.       x% = Columns% * Picture1.Width
  209.       Y% = Row% * Picture1.Height
  210.       
  211.       If Flipped%(Cell%) Then
  212.       '* Cell is currently flipped, so copy corresponding Icon
  213.       '* from IconBitmap to middle of "working" Picture control
  214.       '* then Copy the bitmap of the Working picture control to
  215.       '* the form
  216.         Z% = BitBlt(Picture3.hDC, 18, 18, 32, 32, Picture4.hDC, Cell% * 32, 0, SRCCOPY)
  217.         Z% = BitBlt(hDC, x%, Y%, Picture1.Width, Picture1.Height, Picture3.hDC, 0, 0, SRCCOPY)
  218.       Else
  219.         
  220.       '* Cell is not flipped so display normal cell background.
  221.         Z% = BitBlt(hDC, x%, Y%, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, SRCCOPY)
  222.       End If
  223.       Cell% = Cell% + 1
  224.     Next Columns%
  225.   Next Row%
  226. End Sub
  227.